import http from "../../../../class/Utils/Http"
import tips from "../../../../class/Utils/Tips"

Page({
    data: {
        s: 1,
        searchtag: 0,
        selecttype: ['看过我的', '我看过的'],
        inputtext: '',
        selecttypeindex: '0',
        currentTab: 0,
        page:1,
        lit:30,
        lock:1,
        scrollTop:200,
        toView:'A',
    },
    onLoad: function (get) {
        var that = this
      var getcurrentTab = get.currentTab
      console.log(get.currentTab)
      if (getcurrentTab != undefined){
        that.setData({
          currentTab: get.currentTab
        })
      }
        that.setData({
            mid: get.mid,
        })

      //显示加载中
      tips.loading()

        var alphabit = []
        for (var i = 65; i < 91; i++) {
            alphabit.push(String.fromCharCode(i))
        }
        alphabit.push("#")
        that.setData({
            alphabit: alphabit
        })
        that.Huoquheadheight()
        var user = wx.getStorageSync('user');
        //获取我的客户数据
        var data = {
            uid: user.userid,
            p: that.data.page,
            l: that.data.lit
        }
        http.req("/Mingpian/look_me", data, function (res) {
          
            console.log(res)
            if (res.code ==1) {
                that.setData({
                    lista: res.client,
                    s:1
                })
            }else{
                that.setData({
                    s:2
                })
            }

        })
        // //获取我看过的数据
        // var data = {
        //     userid: user.userid,
        //     type: 1,
        //     mid: that.data.mid
        // }
        // http.req("/Mingpian/sc_list", data, function (res) {
        //     //console.log(res.data)
        //     if (res.code == '1') {
        //
        //         that.setData({
        //             listb: res.data,
        //             ss:1
        //         })
        //     } else {
        //         that.setData({
        //             ss:4
        //         })
        //     }
        //
        // })
this.listlist(this)
        //获取我看过的数据
        var data = {
            uid: user.userid,
            type: 0,
            mid: that.data.mid
        }
        http.req("/Mingpian/sc_list", data, function (res) {
            console.log(res.data)
            if (res.code == '1') {

                that.setData({
                    listc: res.data,
                    sss:1
                })
            } else {
                that.setData({
                    sss:4
                })
            }
          
        })
        //console.log("到哪啦")
      //关闭加载中
      tips.loaded()
    },
    listlist: function (that) {
        var user = wx.getStorageSync('user')
        var data = {
            uid: user.userid
        }
        http.reqload("/Api/haoyou_list", data, function (res) {
            console.log(res)
            //console.log(res.list.length)
            if(res.list.length <1){
                that.setData({
                    nodata: true,
                    ss:3
                })
            }else{
                that.setData({
                    ss:1
                })
            }
            that.setData({
                list: res.list
            })
        })
    },

    next:function () {
        var that = this
        var lock = that.data.lock
        if(lock == '1'){
            tips.loading("加载中..")
            var p = that.data.page
            p++
            that.setData({
                page:p
            })
            var user = wx.getStorageSync('user');
            var data = {
                uid: user.userid,
                p: p,
                l: that.data.lit
            }
            var lista = that.data.lista
            http.req("/Mingpian/look_me", data, function (res) {
                //console.log(res)
                if (res.code==1) {
                    for (var i = 0; i < res.client.length; i++) {
                        lista.push(res.client[i])
                    }
                    that.setData({
                        lista: lista
                    })

                }else{
                    that.setData({
                        lock:2
                    })
                }


            })
            tips.loaded()
        }

    },
    onReachBottom: function () {
        //console.log(123)
        // var that = this
        // var thistag = that.data.selecthangye
        // if (thistag == true) {
        //     return false;
        // }
        //
        // wx.showLoading({
        //     title: '加载中',
        // })
        // var param = that.data.param
        // param.page++
        // that.setData({
        //     param: param
        // })
        //
        // var list = that.data.list
        // //that.nav(param);
        //
        // http.reqload("/syq/trade", param, function (res) {
        //     //console.log(param);
        //     for (var i = 0; i < res.docs.length; i++) {
        //         res.docs[i].changduans = 0;
        //         res.docs[i].liuyan_state = 0;   // 留言是否展开
        //         res.docs[i].liuyan_gengduo = 0; //留言是否大于5条
        //         res.docs[i].liuyan_list  = [];  //已留言内容
        //         res.docs[i].liuyan_content = ''; //正在留言内容
        //         res.docs[i].liuyan_disabled = false; //正在按钮状态
        //         list.push(res.docs[i])
        //     }
        //     that.setData({
        //         list: list
        //     })
        //     wx.hideLoading()
        // })
    },
    //选择搜索分类
    bindPickerChange: function (e) {
        var that = this
        //console.log('picker发送选择改变，携带值为', e.detail.value)
        that.setData({
            selecttypeindex: e.detail.value
        })
    },
    //获取搜索框内容
    bindKeyInput: function (e) {
        var that = this
        var thisvalue = e.detail.value
        that.setData({
            inputtext: thisvalue
        })
        //console.log(that.data.inputtext)

        if (that.data.inputtext == '') {
            that.setData({
                s: 1
            })
        } else {
            return
        }
    },
    //提交搜索
    searchsubmit: function (e) {
        var that = this
        var user = wx.getStorageSync('user');
        var title = that.data.inputtext;
        var type = that.data.selecttypeindex
        var data = {
            userid: user.userid,
            type: that.data.selecttypeindex,
            title: title,
            mid: that.data.mid
        }
        http.req("/Mingpian/sc_list", data, function (res) {
            //console.log(res.data)
            if (res.code == '1') {
                that.setData({
                    s: 1,
                    list: res.data
                })
            } else {

                that.setData({
                    s: 3
                })
            }

        })
    },
    goto_card: function (e) {
        var that = this
        var index = e.currentTarget.dataset.index
        var currentTab = that.data.currentTab

        if (currentTab == 0) {
            var list = that.data.lista
            if (list[index].mingpianid > 0) {
                tips.goto("/pages/mingpian/card/card?id=" + that.data.lista[index].mingpianid);
            } else {
                tips.error("用户未设置名片")
            }
        }
        if (currentTab == 1) {
            var list = that.data.listb
            if (list[index].mingpianid > 0) {
                tips.goto("/pages/mingpian/card/card?id=" + that.data.listb[index].mingpianid);
            } else {
                tips.error("用户未设置名片")
            }
        }

    },
    goto_card_huoban:function (e) {
        var that = this
        var friend_login = e.currentTarget.dataset.friend_login
        http.req("/Mingpian/pd_card_id",{friend_login:friend_login},function (res) {
            if(res.code ==200){
                tips.goto("/pages/mingpian/card/card?id=" + res.mingpianid);
            }else{
                tips.error("暂无名片")
            }
        })
    },
    goto_card_qianzai:function (e) {
        var that = this
        var mingpianid = e.currentTarget.dataset.mingpianid
        if(mingpianid > 0){

                tips.goto("/pages/mingpian/card/card?id=" + mingpianid);
            }else{
                tips.error("暂无名片")
            }
    },
    //滑动切换
    swiperTab: function (e) {
        var that = this;
        that.setData({
            currentTab: e.detail.current
        });
    },
    //点击切换
    changeTab: function (e) {
        var that = this;
        //console.log(e)
        if (that.data.currentTab === e.currentTarget.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.currentTarget.dataset.current
            })
        }
    },
    /*
     删除收藏
     */
    del: function (e) {
        var that = this
        var user = wx.getStorageSync("user")
        var id = e.currentTarget.dataset.id
        var name = e.currentTarget.dataset.name
        var index = e.currentTarget.dataset.index
        tips.modal("是否删除好友", true, 'function', false, function () {
            var data = {
                uid: user.userid,
                id: id,
                poster: name
            }

            http.req("/Api/haoyou_del", data, function (res) {
                if (res.code == '220') {
                    tips.ok(res.msg_val)
                    that.listlist(that)
                } else {
                    tips.error(res.msg_val)
                }
            })
        })
    },
    //圈成员字母查找
    zimuscroll: function (e) {
        var that = this
        var thiszimu = e.currentTarget.dataset.zimu
 
        console.log(thiszimu)

        that.setData({
          toView: thiszimu
        })

        return
        if (thiszimu == '#')
            thiszimu = ''


        //获取当前选择字母的节点 begin
        wx.createSelectorQuery().selectAll('.zimu' + thiszimu).boundingClientRect(function (rects) {

            rects.forEach(function (rect) {
                var zimujuli = rect.top

                var dataheadheight = that.data.headheight


                //console.log(zimujuli)
                //console.log(dataheadheight)
                var scrollweizhi = zimujuli - dataheadheight

                
                // wx.pageScrollTo({
                //     scrollTop: scrollweizhi + that.data.scrollNow,
                // })
            })
        }).exec()
        //获取当前选择字母的节点 end


    },
    //获取顶部高度
    Huoquheadheight: function () {
        var that = this
      wx.createSelectorQuery().selectAll('.el-topmenu').boundingClientRect(function (rects) {
            rects.forEach(function (rect) {
                that.setData({
                    headheight: rect.height
                })
            })
        }).exec()
    },
    onPageScroll: function (res) {
        var that = this;
        var topscroll = res.scrollTop;
        //console.log(topscroll)
        this.setData({

            scrollNow: topscroll

        })
    },


})